<?php
error_reporting(0);

header("Content-type: image/png");
$im = @imagecreate(50, 23)  or die("Cannot Initialize new GD image stream");

$background_color = imagecolorallocate($im, 150, 150, 150);
$gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
$text_color = imagecolorallocate($im, 255, 128, 0);

imagefilledrectangle($im,0,0,51,24,$gray_dark);
imagefilledrectangle($im,1,1,50,23,$background_color);

require_once("functions.php");

$page = $_REQUEST['page'];
list($www,$wwwN) = get_domain($page);

//$www = 'www.ourwebstudio.com';

if ( empty($www) ) {
    imagestring($im, 5, 5, 3,  "0/10", $text_color);
	imagepng($im);
	imagedestroy($im);
	die;
}
$pingurl = 'http://www.digitalpoint.com/tools/webrank/?url='.$www;
$c = file_get_contents($pingurl);

if ( $c === false ) {
    imagestring($im, 5, 5, 3,  "unable", $text_color);
	imagepng($im);
	imagedestroy($im);
	die;
}
//explode('/graphic\.php\?wr\=([0-9])*\"/', $c, $match);

$rstr = 'graphic.php?wr=';
$pos = strpos($c, $rstr);

if ($pos === false){
    imagestring($im, 5, 5, 3,  "0/10", $text_color);
	imagepng($im);
	imagedestroy($im);
	die;
}

$pr = substr($c, $pos+strlen($rstr), 3);


imagestring($im, 5, 5, 3,  intval($pr).'/10', $text_color);
imagepng($im);
imagedestroy($im);
?>